/*
 * \brief  PS/2 driver for x86
 * \author Norman Feske
 * \date   2007-09-21
 */

/*
 * Copyright (C) 2007-2009 Norman Feske
 * Genode Labs, Feske & Helmuth Systementwicklung GbR
 *
 * This file is part of the Genode OS framework, which is distributed
 * under the terms of the GNU General Public License version 2.
 */

#include <base/env.h>
#include <base/printf.h>
#include <base/sleep.h>
#include <input/component.h>
#include <cap_session/connection.h>

#include "i8042.h"
#include "ps2_keyboard.h"
#include "ps2_mouse.h"
#include "irq_handler.h"

using namespace Genode;

static Event_queue ev_queue;


int event_pending() { return !ev_queue.empty(); }
Input::Event get_event() { return ev_queue.get(); }


int main(int argc, char **argv)
{
	I8042 i8042;

	Serial_interface *kbd = i8042.kbd_interface();
	Serial_interface *aux = i8042.aux_interface();

	Ps2_mouse    ps2_mouse(*aux, ev_queue);
	Ps2_keyboard ps2_keybd(*kbd, ev_queue, i8042.kbd_xlate());

	Irq_handler ps2_mouse_irq(12, ps2_mouse);
	Irq_handler ps2_keybd_irq( 1, ps2_keybd);

	/*
	 * Initialize server entry point
	 */
	static Msgbuf<256>             snd_msg, rcv_msg;
	static Server_activation<4096> sa(&snd_msg, &rcv_msg);
	static Cap_connection          cap;
	static Server_entrypoint       ep(&cap, &sa);

	/*
	 * Let the entry point serve the input root interface
	 */
	static Input::Root input_root(&ep, env()->heap());
	Root_capability input_root_cap = Root_capability(ep.manage(&input_root));
	env()->parent()->announce(Input::Session::service_name(), input_root_cap);

	Genode::sleep_forever();
	return 0;
}
